package com.ksp.api;

import static com.ksp.com.KSPCOM_BasConst.SES_TKN;
import static com.ksp.com.KSPCOM_BasConst.USR_OAM;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import com.ksp.dom.KSPDOM_ResDta;
import com.ksp.dom.KSPDOM_User;

public class KSPAPI_UsrAuth {

	public static boolean checkUsr(ServletRequest request, String pToken) {
		Object wPamUsr;
		KSPDOM_User wExiOam;
		try {
			//判断登录用户
			HttpServletRequest hreq = (HttpServletRequest) request;
			wPamUsr = hreq.getSession().getAttribute(SES_TKN + ":" + pToken);
			 wExiOam = (KSPDOM_User)hreq.getSession().getAttribute(USR_OAM);
			if (wExiOam.getUsroam().equals(wPamUsr)) {
				return true;
			}
		} catch (Exception e) {
			return false;
		}
		
		return false;
	}


	public static String getUsr(ServletRequest request) {
		HttpServletRequest hreq = (HttpServletRequest)request;
		KSPDOM_User wUser = (KSPDOM_User)hreq.getSession().getAttribute(USR_OAM);
		return wUser.getUsroam();
	}
	
	public static KSPDOM_User getUsrInf(ServletRequest request) {
		HttpServletRequest hreq = (HttpServletRequest)request;
		KSPDOM_User wUser = (KSPDOM_User)hreq.getSession().getAttribute(USR_OAM);
		return wUser;
	}
	
	public static void delUsr(ServletRequest request) {
		HttpServletRequest hreq = (HttpServletRequest)request;
		hreq.getSession().removeAttribute(USR_OAM);
	}
	
}
